<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\api\controller;

use app\common\controller\Api;
use app\common\manager\BaseManager;
use app\common\manager\CaptainManager;
use app\common\manager\prepay\PrepayManager;
use think\Config;
use think\Exception;

/**
 * 充值
 */
class Recharge extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();

        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

    }

    /**
     * type 支付平台 1=支付宝,2=微信
     * method 支付类型
     * money 金额
     * relationId
     * @return void
     */
    public function order(){
        $post = $this->request->post();
        $money = $post['money'] ?? 0.01;
        try {
            PrepayManager::order($this->user,$post);
            $result = PrepayManager::getResult();
            if ($result['code']==BaseManager::$successCode){
                $this->success($result['message'],$result['data']);
            }
        }catch (Exception $exception){
            $this->error($exception->getMessage());
        }

    }

    /**
     * 获取入驻信息
     * @return void
     */
    public function applyInfo()
    {
        $userId = $this->user_id;
        try {
            $result = CaptainManager::getCaptain($userId);
            if ($result['code'] == 1) {
                $this->success($result['message'],$result['data']);
            }else{
                throw new Exception($result['message']);
            }
        }catch (Exception $exception){
            $this->error($exception->getMessage());
        }
    }
}
